package cn.e4j.modular.crm.controller;

import cn.e4j.core.base.controller.BaseController;
import cn.e4j.core.dto.impl.Dto;
import cn.e4j.core.dto.requestDtoResolver.DtoParam;
import cn.e4j.core.dto.requestDtoResolver.DtoWapper;
import cn.e4j.core.reqres.response.PageReData;
import cn.e4j.core.reqres.response.ResponseData;
import cn.e4j.core.reqres.response.SuccessResponseData;
import cn.e4j.modular.crm.entity.GwdgT;
import cn.e4j.modular.crm.service.impl.GwdgTServiceImpl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * 外部返利维护
 * Created by miaoyl on 2019-04-29.
 */
@Controller
@RequestMapping("/crm/gwdc007")
public class Gwdc007Controller extends BaseController {

    @Autowired
    private GwdgTServiceImpl gwdgTService;

    /**
     * 跳转外部返利维护管理页面
     */
    @RequiresPermissions("crm:gwdc007:init")
    @RequestMapping(value = {"", "init"})
    public String index() {
        return "/pc/crm/gwdc007.html";
    }

    /**
     * 查询外部返利维护信息列表
     */
    @RequestMapping("/getGwdglist")
    @RequiresPermissions("crm:gwdc007:init")
    @ResponseBody
    public ResponseData getGwdglist(@DtoParam DtoWapper dtoWapper) {
        Page<Object> page = dtoWapper.getPage();
        Dto inDto = dtoWapper.getDto();
        List<Map<String, Object>> result = gwdgTService.getGwdglist(page, inDto);
        return new PageReData(page, result);
    }

    /**
     * 新增
     */
    @RequestMapping("/add")
    @RequiresPermissions("crm:gwdc007:init")
    @ResponseBody
    public ResponseData add(GwdgT gwdgT) {
        gwdgTService.add(gwdgT);
        return SUCCESS_TIP;
    }

    /**
     * 修改
     */
    @RequestMapping("/edit")
    @RequiresPermissions("crm:gwdc007:init")
    @ResponseBody
    public ResponseData edit(GwdgT gwdgT) {
        gwdgTService.edit(gwdgT);
        return SUCCESS_TIP;
    }

    /**
     * 删除
     */
    @RequestMapping("/del")
    @RequiresPermissions("crm:gwdc007:init")
    @ResponseBody
    public ResponseData del(GwdgT gwdgT) {
        gwdgTService.del(gwdgT);
        return SUCCESS_TIP;
    }

    /**
     * 批量删除数据
     */
    @RequestMapping("/delDataBatch")
    @RequiresPermissions("crm:gwdc007:init")
    @ResponseBody
    public ResponseData deleteDataBatch(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        List<GwdgT> gwdgTList = inDto.getReqList(GwdgT.class);
        gwdgTService.deleteDataBatch(gwdgTList);
        return SUCCESS_TIP;
    }

    /**
     * 查询系统外数据类型
     */
    @RequestMapping("/getGwdelist")
    @ResponseBody
    public ResponseData getGwdelist(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        List<Dto> result = gwdgTService.getGwdelist(inDto);
        return new SuccessResponseData(result);
    }
}
